// https://www.acwing.com/problem/content/790/

#include <iostream>
#include <vector>

using namespace std;

// 力扣中一样的题 https://leetcode.cn/problems/shu-zu-zhong-de-ni-xu-dui-lcof/



void merge(vector<int>& nums, const int left, const int mid, const int right, int& cnt, vector<int>& tmp) {
    // 合并临时数组
    int t1 = left; // 左半部分的索引
    int t2 = mid + 1; // 右半部分的索引
    int k = left; // 合并后数组的索引

    while (t1 <= mid && t2 <= right) {
        if (nums[t1] <= nums[t2]) {
            tmp[k++] = nums[t1++];
        } else {
            tmp[k++] = nums[t2++];
            cnt += mid - t1 + 1;
        }
    }

    while (t1 <= mid) {
        nums[k++] = nums[t1++];
    }
    while (t2 <= right) {
        nums[k++] = nums[t2++];
    }
}


void merge_sort(vector<int>& nums, int left, int right, int& cnt, vector<int>& tmp) {
    if (left < right) {
        // 找到中间索引
        int mid = left + (right - left) / 2;

        // 分别对左右两半进行排序
        merge_sort(nums, left, mid, cnt, tmp);
        merge_sort(nums, mid+1, right, cnt, tmp);

        // 合并已排序的两半
        merge(nums, left, mid, right, cnt, tmp);
    }
}

/**
  6
  2 3 4 5 6 1
  [5]
 */
int main() {
    int n;
    cin>>n;
    vector<int> nums(n);
    for (int i = 0; i < n; ++i) {
        cin>>nums[i];
    }
    cout<<count_inverse(nums)<<endl;
    return 0;
}
